package com.io;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 输入流和输出流   读取和携入文件  FileInputStream FileOutputStream
 */
public class ReadAndWrite {

    static String readFilePath = "E:\\yangjl\\元尊.txt";
    static String writeFilePath = "E:\\yangjl\\元尊_bak.txt";

    String readFile(String flePath) {
        FileInputStream fileInputStream = null;

        String res = null;
        try {
            fileInputStream = new FileInputStream(flePath);

            int available = fileInputStream.available();
            System.out.println(available+"---"+Integer.MAX_VALUE);
            byte[] bytes = new byte[available];

            fileInputStream.read(bytes);

            res = new String(bytes);

            System.out.println(res);

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                fileInputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
        return res;
    }

    void writeFile(String content, String writeFilePath) {
        FileOutputStream fileOutputStream = null;
        try {
            fileOutputStream = new FileOutputStream(writeFilePath);

            byte[] bytes = content.getBytes();

            fileOutputStream.write(bytes);

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

 /*   public static void main(String[] args) {
        ReadAndWrite readAndWrite = new ReadAndWrite();

        String res = readAndWrite.readFile(readFilePath);

        readAndWrite.writeFile(res, writeFilePath);

    }*/
}
